﻿using MediatR;
using WMS.Domain;
using WMS.ErrorCode;
using WMS.Infrasturcture.Interfaces;
using WMS.WebApiRead.Application.Command;

namespace WMS.WebApiRead.Application.Commandhandler
{
    /// <summary>
    /// 处理 <see cref="WarehousesupervisorsQueryCommand"/> 查询命令的处理器
    /// </summary>
    public class WarehousesupervisorsQueryCommandhandler : IRequestHandler<WarehousesupervisorsQueryCommand, ApiResult<List<WarehouseSupervisor>>>
    {
        private readonly IBaseRepository<WarehouseSupervisor> warehouseSupervisorrepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="warehouseSupervisorrepository"></param>
        public WarehousesupervisorsQueryCommandhandler(IBaseRepository<WarehouseSupervisor> warehouseSupervisorrepository)
        {
            this.warehouseSupervisorrepository = warehouseSupervisorrepository;
        }
        /// <summary>
        /// 处理 <see cref="WarehousesupervisorsQueryCommand"/> 命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<List<WarehouseSupervisor>>> Handle(WarehousesupervisorsQueryCommand request, CancellationToken cancellationToken)
        {
            try
            {

                var warehouseSupervisors = warehouseSupervisorrepository.GetAll().ToList();
                return new ApiResult<List<WarehouseSupervisor>>
                {
                     Code=ApiResultEnum.查询成功,
                      Message="查询仓库管理员成功",
                      Data=warehouseSupervisors


                };

            }
            catch (Exception ex)
            {
                 

                throw;
            }
        }
    }
}
